package org.example.democode.movierental;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liyishan
 * @date 2023/6/8 09:59
 * @apiNote
 */
@Data
public class Customer {
    private String name;
    private List<Rental> rentals = new ArrayList<>();

    public void addRental(Rental rental) {
        this.rentals.add(rental);
    }

    public Customer(String name) {
        this.name = name;
    }
    public String getName() {
        return name;
    }


    public void statement() {
        System.out.println(this.getName() + "的租聘记录");
        for (Rental each : rentals) {
            double thisAmount = each.getCharge();
            System.out.println(each.getMovie().getTitle()+":"+thisAmount);
        }
        int frequentRenterPoints = getFrequentRenterPoints(rentals);
        System.out.println("积分:" + frequentRenterPoints);
        double frequentRenterCharge = getFrequentRenterCharge(rentals);
        System.out.println("价格:" + frequentRenterCharge);

    }


    /**
     * 获取积分总额
     *
     * @param rentals
     * @return
     */
    private int getFrequentRenterPoints(List<Rental> rentals) {
        return rentals.stream()
                .mapToInt(Rental::getPoint)
                .sum();
    }


    /**
     * 获取积分总额
     *
     * @param rentals
     * @return
     */
    private double getFrequentRenterCharge(List<Rental> rentals) {
        return rentals.stream()
                .mapToDouble(Rental::getCharge)
                .sum();
    }

    public static void main(String[] args) {
        Movie movie1 = new Movie("儿童片", Movie.CHILDRENS);
        Movie movie2 = new Movie("普通片", Movie.REGULAR);
        Movie movie3 = new Movie("新片", Movie.NEW_RELEASE);
        Customer customer = new Customer("张三");
        customer.addRental(new Rental(movie1, 1));
        customer.addRental(new Rental(movie2, 3));
        customer.addRental(new Rental(movie3, 5));
        customer.statement();
    }
}
